document.addEventListener('DOMContentLoaded', () => {
    // 获取所有导航链接
    const navLinks = document.querySelectorAll('.nav-item');
    
    // 为每个链接添加点击事件
    navLinks.forEach(link => {
        link.addEventListener('click', e => {
            e.preventDefault(); // 阻止默认跳转
            const target = e.target.href;
            
            // 添加过渡动画
            document.body.classList.add('page-transitioning');
            
            // 等待动画完成后跳转
            setTimeout(() => {
                window.location.href = target;
            }, 500);
        });
    });
    
    // 页面加载时的入场动画
    window.addEventListener('load', () => {
        const transition = document.querySelector('.page-transition');
        if (transition) {
            transition.classList.add('entering');
        }
    });
});

/**
 * 退出登录
 */
async function logout() {
    if (!confirm('确定要退出登录吗？')) {
        return;
    }

    try {
        const response = await fetch('http://localhost:9595/api/user/logout', {
            method: 'POST',
            credentials: 'include'
        });
        
        const data = await response.json();
        if (data.code === 10000) {
            alert('已成功退出登录');
            window.location.href = 'login.html';
        } else {
            alert('退出登录失败，请重试');
        }
    } catch (error) {
        alert('网络错误，请稍后重试');
        console.error('Logout failed:', error);
    }
}

// 如果有退出按钮，可以添加事件监听
const logoutBtn = document.querySelector('.logout-btn');
if (logoutBtn) {
    logoutBtn.addEventListener('click', logout);
} 